﻿using CommonGenerateClient.Win.Models;
using System.Collections.Generic;
using System;
using System.Collections.ObjectModel;

namespace CommonGenerateClient.Win.ViewModel
{
    public class VMDBConfig : VMBase
    {
        public ObservableCollection<VMDBConfigItem> DBList { get; set; }

        public VMDBConfig()
        {
            Load();
        }

        private async void Load()
        {
            try
            {
                //获取数据库列表
                var rawTableList = DBConfigSingleton.Instance.DBConfig;

                if (rawTableList == null || rawTableList.Count == 0)
                {
                    return;
                }

                var tableList = new List<VMDBConfigItem>();
                foreach (var item in rawTableList)
                {
                    tableList.Add(new VMDBConfigItem { ConnectionType = item.ConnectionType, ConnectionString = item.ConnectionString, DBName = item.DBName });
                }

                DBList = new(tableList);
            }
            catch (Exception e)
            {
                HandyControl.Controls.Growl.Error(e.Message);
            }
        }
    }
}
